<?php
/**
 * BootAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using BootAdmin.
 *
 * @Author G.r<root@BootAdmin.com>
 */

declare (strict_types=1);

namespace app\admin\controller\auth;

use app\admin\Base;
use app\admin\logic\DeptLogic;
use app\admin\validate\DeptValidate;

/**
 * 部门控制器
 */
class Dept extends Base
{
    protected DeptLogic $logic;

    protected DeptValidate $validate;

    /**
     * 初始化
     */
    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->logic = new DeptLogic();
        $this->validate = new DeptValidate();
    }

    /**
     * 列表
     */
    public function index()
    {
        $params = $this->validate->go();
        return $this->data($this->logic->list($params));
    }

    /**
     * 回收站
     */
    public function recycle()
    {
        $params = $this->validate->go();
        return $this->data($this->logic->list($params, true));
    }

    /**
     * 快捷列表
     */
    public function getList()
    {
        $params = $this->validate->go();
        return $this->data($this->logic->getList($params));
    }

    /**
     * 详情
     */
    public function read()
    {
        $params = $this->validate->go();
        return $this->data($this->logic->read($params['id']));
    }

    /**
     * 新增
     */
    public function add()
    {
        $params = $this->validate->post()->goCheck('add');
        $this->logic->add($params);
        return $this->success('新增成功');
    }

    /**
     * 编辑
     */
    public function edit()
    {
        $params = $this->validate->post()->goCheck('edit');
        $this->logic->edit($params);
        return $this->success('修改成功');
    }

    /**
     * 删除
     */
    public function delete()
    {
        $params = $this->validate->get()->goCheck('delete');
        $this->logic->del($params['id']);
        return $this->success('删除成功');
    }

    /**
     * 真实删除
     */
    public function realDel()
    {
        $params = $this->validate->get()->goCheck('delete');
        $this->logic->realDel($params['id']);
        return $this->success('删除成功');
    }

    /**
     * 恢复
     */
    public function recovery()
    {
        $params = $this->validate->get()->goCheck('recovery');
        $this->logic->recovery($params['id']);
        return $this->success('恢复成功');
    }

    /**
     * 字段修改
     */
    public function modify()
    {
        $params = $this->validate->post()->goCheck('modify');
        $this->logic->modify($params);
        return $this->success('修改成功');
    }
}